package com.example.springframeworklearning.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.format.FormatterRegistry;
import org.springframework.format.datetime.DateTimeFormatAnnotationFormatterFactory;
import org.springframework.format.datetime.standard.DateTimeFormatterRegistrar;
import org.springframework.format.support.FormattingConversionService;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.time.format.DateTimeFormatter;

/**
 * @author luo
 * @since 2022/9/21 13:52
 */
@Configuration
@EnableWebMvc
public class WebConfig implements WebMvcConfigurer {


    @Override
    public void addFormatters(FormatterRegistry registry) {
        /**
         * mvc 但是配置了没有效果
         * 全局配置日期格式化
         * 参考：https://docs.spring.io/spring-framework/docs/current/reference/html/web.html#mvc-config-conversion
         */
        DateTimeFormatterRegistrar registrar = new DateTimeFormatterRegistrar();
        registrar.setDateFormatter(DateTimeFormatter.ISO_TIME);
//        registrar.setUseIsoFormat(true);
        registrar.registerFormatters(registry);
    }
}
